#!/usr/bin/python3
# -*- coding: UTF-8 -*- 

import os, re
count = 0
folder_path = "dictionary/zh_dict//"

with open(os.path.join(folder_path, "zh_word_base_phoneme.dict"), "w") as fTgtWord:
	with open(os.path.join(folder_path, "zh_phrase_base_phoneme.dict"), "w") as fTgtPhrase:

		with open(os.path.join(folder_path, "word2phone_fs2.dict"), "r") as fSrc:
			for line in fSrc.readlines():
				line = line.strip('\n')  #去掉列表中每一个元素的换行符
				parts = line.split(" ")

				key = parts[0]

				first = True
				value = ""
				for p in parts:
					if p == "":
						continue
					elif first == True:
						first = False
						continue
					else:
						value += p + " "

				value = value[:-1]


				line = key + "\t" + value

				if(1 == len(key)):		#单字
					fTgtWord.write(line + "\n")
				else:					#多字
					match = re.findall(r"零|一|二|三|四|五|六|七|八|九|十|百|千|万|亿", key)
					if len(match) >= len(key)-1:
						count += 1
						print(count , key, match)
						continue
					fTgtPhrase.write(line + "\n")
				print(line)
